package com.gjs.common.manager.response;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel
public class RspBody<T> {

    @ApiModelProperty("请求追踪ID")
    private String traceId;

    @ApiModelProperty("响应码")
    private Integer code;

    @ApiModelProperty("响应信息")
    private String msg;

    @ApiModelProperty("响应数据")
    private T data;

    public RspBody(RspEnum respondInfo, String Msg) {
        this.code = (respondInfo.getResultCode());
        this.msg = (Msg);
    }

    public static RspBody error(String errMsg) {
        return new RspBody(RspEnum.FAIL, errMsg);
    }

    public static RspBody error(RspEnum respondInfo) {
        return new RspBody(respondInfo, respondInfo.getResultMsg());
    }

    public static RspBody error(RspEnum respondInfo,String errMsg) {
        return new RspBody(respondInfo, errMsg);
    }

    public static RspBody forbid() {
        return forbid(RspEnum.FORBID.getResultMsg());
    }

    public static RspBody forbid(String errMsg) {
        return new RspBody(RspEnum.FORBID, errMsg);
    }

    public static RspBody success() {
        return success(null);
    }

    public static<T> RspBody<T> success(T data) {
        RspBody<T> rspBody = new RspBody<>();
        rspBody.setCode(RspEnum.SUCCESS.getResultCode());
        rspBody.setMsg(RspEnum.SUCCESS.getResultMsg());
        rspBody.setData(data);
        return rspBody;
    }
}
